﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Transport.Core.Models.Parcels;
using Transport.Services.Infrastructure;

namespace Transport.Services.Parcels
{
    public class ParcelDeliveryRepository : RepositoryBase<ParcelDelivery>, IParcelDeliveryRepository
    {
        public ParcelDeliveryRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {
        }

        /// <summary>
        /// Search 
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public IQueryable<ParcelDelivery> Search(string text)
        {
            return string.IsNullOrEmpty(text)
                                ? GetAll().Where(p => p.IsDeleted == false).OrderByDescending(p => p.ParcelDeliveryId)
                                : GetAll()
                                .Where(p => p.IsDeleted == false && (
                                 p.Parcel.TrackingNumbers.Contains(text))).OrderByDescending(p => p.ParcelDeliveryId);
        }
    }
}
